package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppDynamic;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 动态
 */
@Repository
public class AfterDynamicDao extends BaseDao<AppDynamic> {

    /**
     * 查询列表
     */
    public List<AppDynamic> findList(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_dynamic where 1=1  ");

        if (!StringEx.isNull(paraMap.get("nick"))) {
            sbStr.append(" and nick = ? ");
            paramList.add(paraMap.get("nick"));
        }

        if (!StringEx.isNull(paraMap.get("status"))) {
            sbStr.append(" and status = ? ");
            paramList.add(paraMap.get("status"));
        }

        if (!StringEx.isNull(paraMap.get("userid"))) {
            sbStr.append(" and userid = ? ");
            paramList.add(paraMap.get("userid"));
        }
        if (!StringEx.isNull(paraMap.get("phone"))) {
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }

        if (!StringEx.isNull(paraMap.get("startDate"))) {
            sbStr.append(" and createtime>=? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (!StringEx.isNull(paraMap.get("endDate"))) {
            sbStr.append(" and createtime<=? ");
            paramList.add(paraMap.get("endDate"));
        }

        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppDynamic.class, splitPage);
    }

    /**
     * 详情
     */
    public AppDynamic get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_dynamic where id = ?  ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppDynamic.class);
    }

    /**
     * 添加/修改
     */
    public void saveOrUpdate(AppDynamic appDynamic) {
        if (appDynamic!=null && appDynamic.getId() != null && appDynamic.getId() > 0) {
            this.update(appDynamic);
        } else {
            appDynamic.setId(this.add(appDynamic));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete from app_dynamic where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    //更新状态(逻辑删除)
    public void updateStatus(Integer id, Integer status) {
        if (id==null || id <= 0 || status==null || status<=0) {
            return;
        }
        String sql = "update app_dynamic set status = ? where id = ?";
        List<Object> paramList = new ArrayList<Object>();
        paramList.add(status);
        paramList.add(id);
        this.update(sql,paramList);
    }

}
